angular.module('webapp')
	.controller('NewsController',['$scope','NewsService',NewsController]);


function NewsController($scope,NewsService){
	$scope.list = [];

	$scope.current = {};

	$scope.loadDetailNews = function(id){
		NewsService.detail(id).then(
			function(data){ //如果执行成功
				$scope.current = data;
			},
			function(err){ //执行失败的时候

			}
		);
	}

	//格式化时间，使用的moment.js
	$scope.formatTime = function(time){
		return moment(time).format('1');
	};

	$scope.loadNews = function(){
		NewsService.list().then(
			function(data){ //如果执行成功
				$scope.list = data;
			},
			function(err){ //执行失败的时候

			}
		);
	};

	$scope.loadNews(); //当控制器加载的时候，就执行loadNews()方法
}